import ItemBaseData from "../data/ItemBaseData";

export default class TxtSp extends Laya.Sprite{
    private mTxt:Laya.Label;
    constructor(){
        super();
        this.mTxt=new Laya.Label();
        this.mTxt.fontSize=30;
        this.mTxt.color="#00ff00";
        this.mTxt.pos(0,0);
        this.addChild(this.mTxt);
    }

    public show(_parent,_x:number,_y:number,_msg:string){
        this.mTxt.text=_msg;
        this.scaleX=this.scaleY=0;
        _parent.addChild(this);
        let tx=_x-30;
        if(tx<0)tx=0;
        this.pos(tx,_y);
        Laya.Tween.to(this,{scaleX:1,scaleY:1},500);
        Laya.timer.once(1000,this,this.remove);
    }

    public remove(){
        Laya.Pool.recover(ItemBaseData.TXT_FLAG,this);
        this.removeSelf();
    }

    public static createByPool():TxtSp{
        let ts:TxtSp=Laya.Pool.getItem(ItemBaseData.TXT_FLAG);
        if(!ts)ts=new TxtSp();
        return ts;
    }
}